<template>
  <div class="shopcar-container">
    <div class="mui-card" v-for="(item, i) in carList" :key="item.id">
      <div class="mui-card-content">
        <div class="mui-card-content-inner goods-info">
          <mt-switch
            v-model="$store.getters.getGoodsSelected[item.id]"
            @change="updataSelected(item.id, $store.getters.getGoodsSelected[item.id])"
          ></mt-switch>
          <img :src="item.thumb_path" alt />
          <div class="info">
            <h4>{{ item.title }}</h4>
            <p>
              <span class="price">￥{{ item.sell_price }}</span>
              <shopcarnumbox :initcount="$store.getters.getCarCount[item.id]" :goodsid="item.id"></shopcarnumbox>
              <a href="#" @click.prevent="remote(item.id, i)">删除</a>
            </p>
          </div>
        </div>
      </div>
    </div>
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner jiesuan">
          <div class="left">
            <p>总计（不包含运费）</p>
            <p>
              已勾选商品
              <span class="red">{{ $store.getters.getGoodsCountAndTotal.count }}</span> 件，总价：
              <span class="red">￥{{ $store.getters.getGoodsCountAndTotal.total }}</span>
            </p>
          </div>
          <mt-button type="danger">去结算</mt-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import shopcarnumbox from "../common/ShopcarNumbox.vue";
export default {
  data() {
    return {
      carList: []
    };
  },
  created() {
    this.getStopCarList();
  },
  components: {
    shopcarnumbox
  },
  methods: {
    getStopCarList() {
      let idAll = [];
      this.$store.state.car.forEach(item => idAll.push(item.id));
      this.$http
        .get("api/goods/getshopcarlist/" + idAll.join(","))
        .then(result => {
          if (result.data.status === 0) {
            this.carList = result.data.message;
          }
        });
    },
    remote(id, index) {
      this.carList.splice(index, 1);
      this.$store.commit("remoteGoodsInfo", id);
    },
    updataSelected(id, selected) {
      this.$store.commit("updataGoodsSelected", {
        id,
        selected
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.shopcar-container {
  background-color: #eee;
  overflow: hidden;
  .goods-info {
    display: flex;
    justify-content: space-between;
    img {
      width: 65px;
      height: 65px;
    }
    .info {
      flex-direction: column;
      display: flex;
      justify-content: space-between;
      h4 {
        font-size: 13px;
        margin-bottom: 3px;
      }
      p {
        text-align: right;
        .price {
          color: red;
        }
      }
    }
  }
  .jiesuan {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .red {
      color: red;
      font-weight: bold;
      font-size: 16px;
    }
  }
}
</style>
